{extend name="$BASE_LIST" /}
{block name="body"}
<link rel="stylesheet" type="text/css" href="__STATIC__/monthPicker/dateRange.css"/>
<link rel="stylesheet" type="text/css" href="__STATIC__/monthPicker/monthPicker.css"/>
<div class="right-main">
    <div class="page_nav" id="js_page_nav"><span class="page_title">认证列表</span></div>
    <div id="js_main_header" class="ui-form main_header">
        <div class="left margin-right-5">
            <input style="width:200px" class="form-control" id="month_picker" size="20" />
        </div>
        <span class="frm_input_box search append">
            <a href="javascript:void(0);" id="js_search" class="frm_input_append">
                <i class="icon wb-search" title="搜索"></i>
            </a>
            <input type="text" id="js_keyword" placeholder="请输入用户名称或手机号或邮箱" value="" class="frm_input" />
        </span>
    </div>
    <table id="grid-table">
        <thead frozen="true">
        <th data-options="field:'username',width:100,align:'center'">用户名称</th>
        </thead>
         <thead >
             <tr>
                <th data-options="field:'phone',width:130, align:'center'">手机号</th>
                <th data-options="field:'to_user',width:130, align:'center',formatter:formatToUser">推荐人</th>
                <th data-options="field:'to_phone',width:130, align:'center',formatter:formatToUserPhone">推荐人手机</th>
                <th data-options="field:'real_name',width:90, align:'center'">真实姓名</th>
                <th data-options="field:'card_no',width:140, align:'center'">身份证号</th>
                <th data-options="field:'is_frozen',width:120,align:'center', formatter:formatStatus">用户状态</th>
                <th data-options="field:'register_time',width:150, align:'center'">注册时间</th>
                <th data-options="field:'_oper',halign:'center',formatter: formatOper">操作</th>
            </tr>
        </thead>
    </table>
</div>

{/block}
{block name="script"}
<script type="text/javascript" src="__STATIC__/monthPicker/dateRange.js"></script>
<script type="text/javascript" src="__STATIC__/monthPicker/monthPicker.js"></script>
<script type="text/javascript">
    var myDate = new Date();
    var month = parseInt(myDate.getMonth()) + 1;
    var toDay = myDate.getFullYear() + '-' + month + '-' + myDate.getDate();
    var dateRange = new pickerDateRange('month_picker', {
        startDate: '2000-01-01',
        endDate: toDay,
        defaultText: ' 至 ',
        theme: 'ta'
    });
    function formatCount(value){
        if(!value){
            return 0;
        }else{
            return value;
        }
    }
    $("#js_addBtn").click(function () {
        if ($(this).hasClass("disabled")) {
            return;
        }
        var url = getURL('add_user');
        openBarWin('添加用户',1000, 500, url, function () {
            reload();
        });
    });
    function formatToUser(value,row,index){
        var text = '<span>'+value+'</span>';
        if(value == null)
            text = '<span>/</span>';
        return text;
    }
    function formatToUserPhone(value,row,index){
        var text = '<span>'+value+'</span>';
        if(value == null)
            text = '<span>/</span>';
        return text;
    }
    function formatOper(value, row, index) {
        var html = '<span class="grid-operation">';
        html += '<button type="button" onclick="auth(' + row['id'] + ')" class="btn btn-xs btn-default edit-btn"><i class="icon wb-edit"></i>操作认证</button>';
        html += '</span>';
        return html;
    }

    function formatStatus(value,row,index){
        var text = '<span style="color:red">正常</span>';
        if(value == '1')
            text = '<span style="color:green">冻结</span>';
        return text;
    }
    function formatAuth(value,row,index){
        var text = '<span style="color:red">未认证</span>';
        if(value == '1') {
            text = '<span style="color:green">已认证</span>';
        }else if(value == '2'){
            text = '<span style="color:yellow">待认证</span>';
        }else if(value == '-1'){
            text = '<span style="color:red">不通过</span>';
        }
        return text;
    }

    $(function () {
        $('#grid-table').datagrid({
            url: getURL('loadList')+'?is_auth=2',
            method: "GET",
            height: getGridHeight(),
            rownumbers: true,
            singleSelect: true,
            remoteSort: false,
            multiSort: true,
            emptyMsg: '<span>无相关数据</span>',
            pagination: true,
            pageSize: 20,
        });
        //设置分页控件
        $('#grid-table').datagrid('getPager').pagination({
            pageSize: 20, //每页显示的记录条数，默认为10
            pageList: [20, 30, 50]
        });
    });

    function formatAuth(value,row,index){
        var text = '<span style="color:red">未认证</span>';
        if(value == '1'){
            text = '<span style="color:green">已认证</span>';
        }else if(value == '2'){
            text = '<span style="color:#ff9b00">待认证</span>';
        }else if(value =='-1'){
            text = '<span style="color:red">不通过</span>';
        }
        return text;
    }

    function change_frozen(id,status){
        var title = '确认要解冻此用户吗?';
        if(status == 1)
            title = '确认要冻结此用户吗?';
        confirm(title, function () {
            var url = getURL('change_frozen');
            $.getJSON(url, {id: id,status:status}, function (json) {
                if (json.success)
                    reload();
                else
                    alert(json.message);
            });
        });
    }
    function edit(id) {
        var url = getURL('edit', 'id=' + id);
        openBarWin('编辑', 1000, 500, url, function () {
            reload();
        }, ['确定','取消']);
    }
    function auth(id) {
        var url = getURL('auth', 'id=' + id);
        openBarWin('认证用户', 1000, 600, url, function () {
            reload();
        }, ['确定','取消']);
    }

    function del(id) {
        confirm("删除后会员数据无法找回。确认要删除此会员吗？", function () {
            var url = getURL('del');
            $.getJSON(url, {id: id}, function (json) {
                if (json.success)
                    reload();
                else
                    alert(json.message);
            });
        });
    }

    $("#js_addBtn").click(function () {
        if ($(this).hasClass("disabled")) {
            return;
        }
        var url = getURL('add_user');
        openBarWin('添加用户',1000, 500, url, function () {
            reload();
        });
    });

    $("#js_search").click(function () {
        reload();
    });

    $("#js_expBtn").click(function () {
        location.href = getURL('export');
    });

    function reload() {
        var keyword = $("#js_keyword").val();
        var month_picker = $("#month_picker").val();
        var arr = month_picker.split(" 至 ");
        var startDate = arr[0];
        var endDate = arr[1];
        $('#grid-table').datagrid('reload', {
            keyword: keyword,
            startDate: startDate,
            endDate: endDate
        });
    }

    
</script>
{/block}